<template>
  <div class="login">
    <div class="login-container" data-v-26084dc2="">
      <div class="head" data-v-26084dc2="">
        <img
          class="logo"
          src="https://s.weituibao.com/1582958061265/mlogo.png"
          data-v-26084dc2=""
        />
        <div class="name" data-v-26084dc2="">
          <div class="title" data-v-26084dc2="">新蜂商城</div>
          <div class="tips" data-v-26084dc2="">Vue3.0 后台管理系统</div>
        </div>
      </div>
      <el-form
        :label-position="labelPosition"
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="120px"
        class="demo-ruleForm"
        :size="formSize"
        status-icon
      >
        <el-form-item label="账号" prop="username">
          <el-input v-model="ruleForm.username" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="ruleForm.password" />
        </el-form-item>
        <h5>登录表示您已同意<b style="color: #409eff">《服务条款》</b></h5>
        <el-form-item class="btn-item">
          <el-button
            class="btn-list"
            type="primary"
            @click="submitForm(ruleFormRef)"
            >立即登录</el-button
          >
        </el-form-item>
        <div>
          <input type="checkbox" />
          下次自动登录
        </div>
      </el-form>
    </div>
  </div>
</template>

<script lang="ts" setup>
import md5 from "js-md5"
import { onMounted, reactive, ref } from "vue";
// import type { FormInstance, FormRules } from "element-plus";
import { login } from "../app/login";
const labelPosition = ref("top");

const formSize = ref("default");
const ruleFormRef = ref();
const ruleForm = reactive({
  username: "admin",
  password: "123456",
  delivery: false,
});
// const passwords = md5.array(ruleForm.password);
onMounted(() => {});

const rules = reactive({
  username: [
    { required: true, message: "请输入账号", trigger: "blur" },
    { min: 3, max: 5, message: "长度为3~5", trigger: "blur" },
  ],
  password: [
    { required: true, message: "请输入密码", trigger: "blur" },
    { min: 3, max: 6, message: "长度为3~6", trigger: "blur" },
  ],
});

const submitForm = async (formEl) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
     if (valid) {
      login({
        loginUserName: ruleForm.username,
        loginPassword: ruleForm.password,
      })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    } else {
      console.log("error submit!", fields);
    }
  });
};

</script>
<style scoped lang="scss">
.login-container[data-v-26084dc2] {
  width: 420px;
  height: 500px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 21px 41px 0 rgb(0 0 0 / 20%);
  position: absolute;
  top: 50%;
  left: 50%;
  //   margin-top: 80px;
  //   margin-left: -210px;
  transform: translate(-50%);

  .head[data-v-26084dc2] {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px 0 20px 0;

    img[data-v-26084dc2] {
      width: 100px;
      height: 100px;
      margin-right: 20px;
    }

    .title[data-v-26084dc2] {
      font-size: 28px;
      color: #1baeae;
      font-weight: 700;
    }

    .tips[data-v-26084dc2] {
      font-size: 12px;
      color: #999;
    }
  }
}
.demo-ruleForm {
  width: 300px;
  margin: auto;
  .btn-item {
    width: 300px;
    margin: auto;
    .btn-list {
      width: 100%;
      background: #1baeae;
    }
  }
}

.login {
  position: relative;
}
</style>
